package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.CartDao;
import dao.CommentDao;
import dao.GoodsDao;
import dao.OrderDao;
import dao.Order_itemDao;
import entity.Cart;
import entity.Comment;
import entity.Goods;
import entity.Order;
import entity.Order_item;
import entity.User;
import net.sf.json.JSONArray;

/**
 * Servlet implementation class CheckoutServlet
 */
@WebServlet("/order_show")
public class OrderSerlet extends HttpServlet {
	private CartDao cartDao = new CartDao();
	private OrderDao orderDao = new OrderDao();
	private Order_itemDao o_itemDao = new Order_itemDao();
	private CommentDao commentDao = new CommentDao();
	private GoodsDao goodsDao = new GoodsDao();
	private Goods goods = new Goods();
	DecimalFormat df = new DecimalFormat("######0.00");
	Order order = new Order();
	Order_item o_item = new Order_item();
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		doPost(req, resp);
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");//这是一个坑，前端传数据进来，要先判断它编码是否正确
		resp.setContentType("text/html;charset=UTF-8");// 防止中文乱码
        // 获取Session中的用户uid
        HttpSession session = req.getSession();
        String ud = (String) session.getAttribute("uid");
        int uid = Integer.parseInt(ud);
        int gid;
		String oid= req.getParameter("oid");
		
		try {
			List<Order_item> orderlist = o_itemDao.queryOidAll(oid);
			
			req.setAttribute("orderlist", orderlist);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		req.getRequestDispatcher("order_show.jsp").forward(req, resp);
	}
	


}
